package net.xconcepts.stockdata.model.models;

import java.util.Map;

import net.xconcepts.stockdata.model.Trader;
import net.xconcepts.stockdata.model.analysis.symbol.Symbol;
import net.xconcepts.stockdata.model.input.HistoricDataFeed;
import net.xconcepts.stockdata.model.tick.SymbolTick;

public abstract class Model {
	
	private final Trader mTrader;
	
	protected abstract Trader getTrader();
	
	public Model() {
		mTrader = getTrader();
	}
	
	public final void runSimulation (HistoricDataFeed feed) {
		while(feed.hasNext()){
			Map<Symbol, SymbolTick> marketTicks = feed.next();
			mTrader.processMarketTick(marketTicks);
			onTick(mTrader, marketTicks);			
		}
	}
	
	protected void onTick(Trader trader, Map<Symbol, SymbolTick> marketTicks) {
		Double value = trader.getPortfolioValue(marketTicks);
		if(value != null) {
			System.out.println(value);
		}
	}
}
